//
//  RCSearchAllCityDataModel.m
//  RocketProject
//
//  Created by Wu Chengwei on 13-7-2.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCSearchAllCityDataModel.h"
#import "FrameworkRelativeDefines.h"
#import "NSArray+EX.h"
#import "NSString+NSString_Ex_.h"

@implementation RCSearchAllCityItem

@synthesize itemID = _itemID;
@synthesize itemName = _itemName;

-(id)init{
    self = [super init];
    if (nil == self) {
        return nil;
    }
    _itemID = nil;
    _itemName = nil;
    return self;
}

-(void)dealloc{
    self.itemID = nil;
    self.itemName = nil;
    [super dealloc];
}

+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    
    RCSearchAllCityItem *retObject = nil;
    retObject = [[RCSearchAllCityItem alloc]init];
    if (nil == retObject) {
        return nil;
    }
    retObject.itemID = [data stringValueForKey:@"id" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.itemName = [data stringValueForKey:@"name" defaultValue:nil operation:NSStringOperationTypeTrim];
    return [retObject autorelease];
}

@end

@implementation RCSearchAllCityDataModel

@synthesize itemKeyArray = _itemKeyArray;
@synthesize itemValueArray = _itemValueArray;

-(id)init{
    self = [super init];
    if (nil == self) {
        return nil;
    }
   
    _itemValueArray = nil;
    _itemKeyArray = nil;
    return self;
}

-(void)dealloc{

    self.itemKeyArray = nil;
    self.itemValueArray = nil;
    [super dealloc];
}

@end

@implementation RCSearchCategoryListDataModel


-(id)init{
    self = [super init];
    if (nil == self) {
        return nil;
    }
    return self;
}

-(void)dealloc{
    
    [super dealloc];
}

+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    RCSearchCategoryListDataModel *retObject = nil;
    retObject = [[RCSearchCategoryListDataModel alloc]init];
    if (nil == retObject) {
        return nil;
    }
    NSArray *dictArray = [data arrayValueForKey:@"data" defaultValue:nil];
    if (nil == dictArray) {
        return nil;
    }
    
    NSMutableArray *labelArray = [[NSMutableArray alloc]initWithCapacity:1];
    NSMutableArray *keyArray = [[NSMutableArray alloc]initWithCapacity:1];
    
    for (int i =0; i< [dictArray count]; i++) {
        NSDictionary *itemDict = [dictArray safeObjectAtIndex:i];
        if (nil == itemDict) {
            continue;
        }
        
        NSString *label = [itemDict stringValueForKey:@"label" defaultValue:nil operation:NSStringOperationTypeTrim];
        if (label != nil && [label isEqualToString:@""]) {
            label = @"租车";
            [labelArray addObject:label];
        }
        
        
        NSArray *categoryArray = [itemDict arrayValueForKey:@"categories" defaultValue:nil];
        if (categoryArray != nil) {
            NSMutableArray *keyItemArray = [[NSMutableArray alloc]initWithCapacity:1];
            for (int j=0 ; j < [categoryArray count] ; j++) {
                NSDictionary *keyItemDict = [categoryArray safeObjectAtIndex:j];
                if (nil == keyItemDict) {
                    continue;
                }
                RCSearchAllCityItem *keyItem = [RCSearchAllCityItem parseDataFromJSON:keyItemDict];
                if (keyItem != nil) {
                    if (![NSString stringIsNullOrEmpty:keyItem.itemName]) {
                        [keyItemArray addObject:keyItem];
                    }
                }
            }
            [keyArray addObject:keyItemArray];
            [keyItemArray release];
            
        }
        
    }
    retObject.itemKeyArray = [NSArray arrayWithArray:labelArray];
    retObject.itemValueArray = [NSArray arrayWithArray:keyArray];
    [labelArray release];
    [keyArray release];
    
    return [retObject autorelease];
}

@end

@implementation RCSearchDistrictListDataModel


-(id)init{
    self = [super init];
    if (nil == self) {
        return nil;
    }
    return self;
}

-(void)dealloc{
    
    [super dealloc];
}

+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    RCSearchCategoryListDataModel *retObject = nil;
    retObject = [[RCSearchCategoryListDataModel alloc]init];
    if (nil == retObject) {
        return nil;
    }
    NSArray *dictArray = [data arrayValueForKey:@"data" defaultValue:nil];
    if (nil == dictArray) {
        return [retObject autorelease];
    }
    
    NSMutableArray *labelArray = [[NSMutableArray alloc]initWithCapacity:1];
    NSMutableArray *keyArray = [[NSMutableArray alloc]initWithCapacity:1];
    
    for (int i =0; i< [dictArray count]; i++) {
        NSDictionary *itemDict = [dictArray safeObjectAtIndex:i];
        if (nil == itemDict) {
            continue;
        }
        
        NSString *label = [itemDict stringValueForKey:@"label" defaultValue:nil operation:NSStringOperationTypeTrim];
        [labelArray addObject:label];
        
        NSArray *categoryArray = [itemDict arrayValueForKey:@"districts" defaultValue:nil];
        if (categoryArray != nil) {
            NSMutableArray *keyItemArray = [[NSMutableArray alloc]initWithCapacity:1];
            for (int j=0 ; j < [categoryArray count] ; j++) {
                NSDictionary *keyItemDict = [categoryArray safeObjectAtIndex:j];
                if (nil == keyItemDict) {
                    continue;
                }
                RCSearchAllCityItem *keyItem = [RCSearchAllCityItem parseDataFromJSON:keyItemDict];
                if (keyItem != nil) {
                    [keyItemArray addObject:keyItem];
                }
            }
            [keyArray addObject:keyItemArray];
            [keyItemArray release];
            
        }
        
    }
    retObject.itemKeyArray = [NSArray arrayWithArray:labelArray];
    retObject.itemValueArray = [NSArray arrayWithArray:keyArray];
    [labelArray release];
    [keyArray release];
    
    return [retObject autorelease];
}

@end
